$(document).ready(function(){
	//$("#searchPrint").load('model.php',{city:'贵阳',model:'api_function',id:'searchweather',usi:Math.random()},
	$("#AreaData").click(function(){
		var key = '745a1415e16c9cb5def7eb240c4b8d73';
		//getJSON
		$.get('http://AreaData.api.juhe.cn/AreaHandler.ashx?action=getArea&areaID=110101',{key:key},
			function(data){alert(typeof(data));
			/*
				if(data != '')
				{
					alert(typeof(data));
				}
				else
				{
					alert('无数据返回！');
				}
			*/
			});
			//alert();
	});
	$("#News").click(function(){
		//alert();
	});
	$("#searchNews").click(function(){
		var search = $('#searchIPT').val();
		//alert(search);
		if(search != '')
		{
			$.post('model.php',{search:search,model:'newapi',usi:Math.random()},
				function(data){
				//alert(data);
				$("#searchPrint").html(data);
			});
		}

	});

	$("#searchPhone").click(function(){
		var cellphone = $('#cellphone').val();
		if(cellphone != '' && cellphone.length > 6)
		{
			$.post('model.php',{cellphone:cellphone,model:'api_function',id:'searchPhone',usi:Math.random()},
				function(data){
				//alert(data);
				$("#searchPrint").html(data);
			});
		}
		else
		{
			$("#searchPrint").html('<p>号码输入有误？</p>');
		}
	});

	$("#searchidcar").click(function(){
		var idcard = $('#idcard').val();
		if(idcard != '' && idcard.length >= 15)
		{
			$.post('model.php',{idcard:idcard,model:'api_function',id:'searchidcar',usi:Math.random()},
				function(data){
				//alert(data);
				$("#searchPrint").html(data);
			});
		}
		else
		{
			$("#searchPrint").html('<p>身份证号码输入有误！</p>');
		}
	});
	$('#defualtWea').load('model.php',{city:'贵阳',model:'api_function',id:'searchweather',usi:Math.random()});//默认加载天气选项
	$('#searchweather').click(function(){
		var city = $('#city').val();
		if(city != '' && city.length >= 2)
		{
			$.post('model.php',{city:city,model:'api_function',id:'searchweather',usi:Math.random()},
				function(data){
				//alert(data);
				$("#searchPrint").html(data);
			});
		}
		else
		{
			$("#searchPrint").html('<p>身份证号码输入有误！</p>');
		}
	});

	$('#sendinfo').click(function(){
		var info = $('#info').val();//alert(info);
		if(info != '')
		{
			$.post('model.php',{info:info,model:'api_function',id:'tuling',usi:Math.random()},
				function(data){
				//alert(data);
				$("#searchPrint").after('<p style="color:#00cc00; margin: 0 0 0 2%;"><span style="font-size:1.2em;color:#0033cc;">我</span>：'+info+'</p>');
				$("#searchPrint").after(data);
				$('#info').val('');
			});
		}
		else
		{
			$("#searchPrint").html('<p>问题输入有误！</p>');
		}
	});
	$(document).keydown(function(event){
		//alert(event.keyCode);
		if(event.keyCode == '13')//enter 键
		{
			$('#searchNews').click();
			var info = $('#info').val();//alert(info);
			if(info.length > 1)
			{
				$.post('model.php',{info:info,model:'api_function',id:'tuling',usi:Math.random()},
					function(data){
					//alert(data);
					$("#searchPrint").after('<p style="color:#00cc00; margin: 0 0 0 2%;"><span style="font-size:1.2em;color:#0033cc;">我</span>：'+info+'</p>');
					$("#searchPrint").after(data);
					$('#info').val('');
				});
			}
			else
			{
				$("#searchPrint").html('<p>问题输入有误！</p>');
			}
		}
		if(event.keyCode == '32')//空格 键
		{
			$('#info').focus();
			$('#idcard').focus();
			$('#city').focus();
			$('#searchIPT').focus();
			$('#cellphone').focus();
		}
		if(event.keyCode == '66')// B 键
		{
			//$('a[href="file.php"]').click();
			//window.location.href = 'file.php';
		}
	});

	$('#getDirveTips').click(function(){
		var subject = $('select[name="getCorser"] option:selected').val();
		var modeltype = $('select[name="getModel"] option:selected').val();
		var testType = $('select[name="testType"] option:selected').val();
		if(subject != '' && modeltype != '')
		{
			$.post('model.php',{model:'api_function',id:'getDirveTips',subject:subject,modeltype:modeltype,testType:testType,uid:Math.random()},
				function(data){
					$('#searchPrint').html(data);
			});
		}
		else
		{
			$('#searchPrint').html('<p>请选择【抽取】条件</p>');
		}
	});
	$('select[name="WeiXunpage"]').change(function(){
		var page = $('select[name="WeiXunpage"] option:selected').val();
		//alert(page);
		$.post('model.php',{model:'api_function',id:'getWeiXunpage',page:page,uid:Math.random()},
				function(data){
					$('#WeixunajaxPrint').html(data);
			});
	});
	$('#WeixunajaxPrint').load('model.php',{model:'api_function',id:'getWeiXunpage',page:1,uid:Math.random()});
	
	//笑话大全
	$('button[name="lastJokes"]').click(function(){
		var page = $('select[name="jokespage"] option:selected').val();
		$.post('model.php',{model:'api_function',id:'lastJokes',item:'lastJokes',page:page,uid:Math.random()},
			function(data){
				$('#jokesAjaxPri').html(data);
		});
	});
	$('button[name="lastserJokes"]').click(function(){
		var page = $('select[name="jokespage"] option:selected').val();//alert(page);
		$.post('model.php',{model:'api_function',id:'lastJokes',item:'lastserJokes',page:page,uid:Math.random()},
			function(data){
				$('#jokesAjaxPri').html(data);
		});
	});
	$('button[name="lastJoketu"]').click(function(){
		var page = $('select[name="jokespage"] option:selected').val();
		$.post('model.php',{model:'api_function',id:'lastJokes',item:'lastJoketu',page:page,uid:Math.random()},
			function(data){
				$('#jokesAjaxPri').html(data);
		});
	});
	$('button[name="lastserJoketu"]').click(function(){
		var page = $('select[name="jokespage"] option:selected').val();
		$.post('model.php',{model:'api_function',id:'lastJokes',item:'lastserJoketu',page:page,uid:Math.random()},
			function(data){
				$('#jokesAjaxPri').html(data);
		});
	});
	$('#jokesAjaxPri').load('model.php',{model:'api_function',id:'lastJokes',item:'lastJokes',page:1,uid:Math.random()});


	//电影
	$('select[name="moviesIndex"]').change(function(){
		$('#MvAjaxPri').html('');
		var Mvindex = $('select[name="moviesIndex"] option:selected').val();
		if(Mvindex == 'Mvname' || Mvindex == 'Mvcity')
		{
			$('#CreateIptMv').html(' <input type="text" name="MvsearthIpt"> ');
		}
		else
		{
			$('#CreateIptMv').html('');
		}
	});
	$('button[name="SearthMv"]').click(function(){
		$('#MvAjaxPri').html('');
		var MvsearthIpt = $('input[name="MvsearthIpt"]').val();
		var SearthMv = $('select[name="moviesIndex"] option:selected').val();
		//alert(MvsearthIpt+'+'+SearthMv);
		/*
		if(SearthMv == 'Mvname' && MvsearthIpt != '')
		{
			$.post('model.php',{model:'api_function',id:'SearthMv',item:'Mvname',Mvname:MvsearthIpt,uid:Math.random()},
				function(data){
					$('#MvAjaxPri').html(data);
			});
		}
		else if(SearthMv == 'Mvcity' && MvsearthIpt != '')
		{
			$.post('model.php',{model:'api_function',id:'SearthMv',item:'Mvcity',Mvcity:MvsearthIpt,uid:Math.random()},
				function(data){
					$('#MvAjaxPri').html(data);
			});
		}
		else
		{
			$('#MvAjaxPri').html('<p>无内容提交！</p>');
		}
		*/


		if(SearthMv == 'Mvname' && MvsearthIpt != '')
		{
			$.post('model.php',{model:'api_function',id:'SearthMv',item:'Mvname',Mvname:MvsearthIpt,uid:Math.random()},
				function(data){
					$('#MvAjaxPri').html(data);
			});
		}
		if(SearthMv == 'Mvcity' && MvsearthIpt != '')
		{
			$.post('model.php',{model:'api_function',id:'SearthMv',item:'Mvcity',Mvcity:MvsearthIpt,uid:Math.random()},
				function(data){
					$('#MvAjaxPri').html(data);
			});
		}
		if(MvsearthIpt == '')
		{
			$('#MvAjaxPri').html('<p>无内容提交！</p>');
		}
	});
});